package com.qyer.commons.concurrent.assemblingline;

import com.google.common.collect.Lists;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import java.util.List;

/**
 * User: Z J Wu Date: 2016/06/06 Time: 10:49 Package: com.qyer.commons.concurrent
 */
public class AssemblerGroup<T> {

  private String name;
  private List<BulkAssembler<T>> assemblers;
  private int acceptBulkSize;

  public AssemblerGroup(String name, int assemblerCount, int acceptBulkSize) {
    this.name = name;
    this.assemblers = Lists.newArrayListWithCapacity(assemblerCount);
    this.acceptBulkSize = acceptBulkSize;
  }

  public void addAssembler(BulkAssembler<T> assembler) {
    if (assembler != null) {
      this.assemblers.add(assembler);
    }
  }

  public BulkAssembler<T> getAssembler(int i) {
    return this.getAssemblers().get(i);
  }

  public String getName() {
    return name;
  }

  public List<BulkAssembler<T>> getAssemblers() {
    return assemblers;
  }

  public int size() {
    return this.assemblers.size();
  }

  public int getAcceptBulkSize() {
    return acceptBulkSize;
  }

  @Override
  public String toString() {
    return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).append("name", name)
                                                                      .toString();
  }
}
